package com.itheima.controller;


import com.itheima.config.UserProperties;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Test2Controller {

    //  @Value() -- 将配置文件中的某些属性值注入到对应的成员变量中
    @Value("${server.port}")
    private String port;

    @Value("${user.username}")
    private String username;

    @Value("${user.age}")
    private Integer age;

    @Value("${user.email}")
    private String email;


    @GetMapping(value = "/test2")
    public Object test2() {

        return "hello" + "," + port;


    }



    @GetMapping(value = "/test3")
    public Object test3() {

        return this.username + "," + this.age + "," + this.email;


    }



    @Resource
    private UserProperties userProperties;

    @GetMapping(value = "/test4")
    public Object test4() {
        return userProperties.getUsername()+","+userProperties.getAge()+","+userProperties.getEmail()
                ;

    }
}